<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #tableTitle>
        <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
        <j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <template #overlay>
            <a-menu>
              <a-menu-item key="1" @click="batchHandleDelete">
                <Icon icon="i-ant-design:delete-outlined" />
                删除
              </a-menu-item>
            </a-menu>
          </template>
          <a-button
            >批量操作
            <Icon style="fontsize: 12px" icon="ant-design:down-outlined" />
          </a-button>
        </a-dropdown>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getActions(record)" />
      </template>

      <!-- 展示退款订单号 -->
      <template #refundOrderNo="{ record }">
        <Row :gutter="[24, 24]" class="order-no">
          <Col :span="4">
            <Tag color="blue">退款</Tag>
          </Col>
          <Col :span="20">
            <Tooltip placement="topLeft">
              <template #title>
                <span>{{ record.refundOrderId }}</span>
              </template>
              <div class="refund-order-no-data">{{ record.refundOrderId }}</div>
            </Tooltip>
          </Col>
        </Row>
        <Row :gutter="[24, 24]">
          <Col :span="4">
            <Tag color="green">商户</Tag>
          </Col>
          <Col :span="20">
            <Tooltip placement="topLeft">
              <template #title>
                <span>{{ record.mchRefundNo }}</span>
              </template>
              <div class="refund-order-no-data">{{ record.mchRefundNo }}</div>
            </Tooltip>
          </Col>
        </Row>
      </template>

      <!-- 展示支付订单号 -->
      <template #payOrderNo="{ record }">
        <Row :gutter="[24, 24]" class="order-no">
          <Col :span="4">
            <Tag color="blue">支付</Tag>
          </Col>
          <Col :span="20">
            <Tooltip placement="topLeft">
              <template #title>
                <span>{{ record.payOrderNo }}</span>
              </template>
              <div class="pay-order-no-data">{{ record.payOrderNo }}</div>
            </Tooltip>
          </Col>
        </Row>
        <Row :gutter="[24, 24]">
          <Col :span="4">
            <Tag color="green">渠道</Tag>
          </Col>
          <Col :span="20">
            <Tooltip placement="topLeft">
              <template #title>
                <span>{{ record.channelPayOrderNo }}</span>
              </template>
              <div class="pay-order-no-data">{{ record.channelPayOrderNo }}</div>
            </Tooltip>
          </Col>
        </Row>
      </template>
    </BasicTable>
    <OrderDetail @register="register" />
  </div>
</template>
<script lang="ts" name="PayRefund" setup>
  import { ref } from "vue"
  import { Tag, Row, Col, Tooltip } from "ant-design-vue"
  import { BasicTable, TableAction } from "/@/components/Table"
  import { useDrawer } from "/@/components/Drawer"
  import OrderDetail from "./OrderDetail.vue"
  import { useGlobSetting } from "/@/hooks/setting"
  import { columns, searchFormSchema } from "./refund.data"
  import { pageRefundOrder, Url } from "/@/api/pay"
  import { useListPage } from "/@/hooks/system/useListPage"
  import { useMessage } from "/@/hooks/web/useMessage"
  import { Icon } from "/@/components/Icon"

  const { createMessage } = useMessage()
  const glob = useGlobSetting()
  const [register, { openDrawer: openDetail }] = useDrawer()
  // 列表页面公共参数、方法
  const { prefixCls, onExportXls, onImportXls, tableContext } = useListPage({
    designScope: "PayRefund",
    tableProps: {
      title: "退款订单列表",
      api: pageRefundOrder,
      columns: columns,
      bordered: false,
      ellipsis: false,
      actionColumn: {
        width: 100,
        title: "操作",
        dataIndex: "action",
        fixed: "right",
        slots: { customRender: "action" },
      },
      formConfig: {
        schemas: searchFormSchema,
        fieldMapToTime: [["fieldTime", ["beginDate", "endDate"], "YYYY-MM-DD"]],
      },
    },
    exportConfig: {
      name: "退款订单",
      url: Url.refundOrderExport,
    },
    importConfig: {
      url: Url.refundOrderImport,
    },
  })

  const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext

  /**
   * 查看
   */
  function handleDetail(record) {
    openDetail(true, {
      record,
      isUpdate: true,
    })
  }
  /**
   * 操作列定义
   * @param record
   */
  function getActions(record) {
    return [
      {
        label: "查看",
        onClick: handleDetail.bind(null, record),
        // ifShow: record.sendStatus == 0
      },
    ]
  }
</script>

<style>
  .order-no {
    margin-bottom: 5px;
  }
  .refund-order-no-data {
    text-align: left;
    width: 100%;
    overflow: hidden;
    margin-left: 5px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .pay-order-no-data {
    text-align: left;
    width: 100%;
    overflow: hidden;
    margin-left: 5px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
</style>
